#!/usr/bin/perl

use strict;
use Astro::Time;
use ATNF::MoniCA;

$Astro::Time::StrZero = 2;

my $server="localhost";

my $mon=monconnect($server);
htmlerror("Could not connect to ATCA monitor host\n") if (!defined $mon);

my @monpoints=qw(site.misc.obs.source
                 site.misc.obs.target1
                 site.misc.obs.target2
                 site.misc.obs.schedFile
                 site.misc.obs.scanStart
                 site.misc.obs.corrConfig
                 site.misc.obs.freq1
                 site.misc.obs.freq2
                 site.misc.obs.rpfits_name
                 site.misc.array);

# convert the starting poll time into MJD
my ($tyear,$tmonth,$tday,$thour,$tminute,$tsecond)=@ARGV;
my $tutfrac=($thour+$tminute/60.0+$tsecond/3600.0)/24.0;
my $tmjd=cal2mjd($tday,$tmonth,$tyear,$tutfrac);
print "start mjd = $tmjd\n";
my $tbat=mjd2bat($tmjd);
print "start bat = $tbat\n";

# check for RPFITS file changes first
my @vals=monfollowing($mon,$tmjd,@monpoints);

#my @vals=monpoll($mon,@monpoints);

for (my $i=0;$i<=$#vals;$i++){
    print $vals[$i]->point." ".mjd2time(bat2mjd($vals[$i]->bat))." ".
	$vals[$i]->val."\n";
}
